import {putAction} from "@/api/manage";
// 前提 要导入JeecgListMixin

export const BoneDisplayMixin = {
  methods: {
    handleIsDisplay(index) {
      if (!this.url.isDisplay) {
        this.$message.error("请设置url.isDisplay!");
        return;
      }
      if (index == null || index === undefined) {
        this.$message.error("请传递索引值");
        return;
      }
      this.dataSource[index].isDisplay === 0 ? this.dataSource[index].isDisplay = 1 : this.dataSource[index].isDisplay = 0;
      putAction(this.url.isDisplay + "/" + this.dataSource[index].id + "/" + this.dataSource[index].isDisplay).then(res => {
        if (res.code === 200) {
          this.$notification.success({message: "提示信息", duration: 2, description: res.message});
        } else {
          this.$notification.error({message: "提示信息", duration: 2, description: res.message});
        }
      });
    },
    handleIsDisplayYesBatch() {
      if (!this.url.isDisplayBatch) {
        this.$message.error("请设置url.isDisplayBatch!");
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
      } else {
        let ids = "";
        for (let a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        let that = this;
        this.$confirm({
          title: "批量显示",
          content: "是否将选中数据都显示?",
          okText: '确认',
          cancelText: '取消',
          onOk: function () {
            that.loading = true;
            putAction(that.url.isDisplayBatch + "/" + ids + "/" + 1).then(res => {
              if (res.code === 200) {
                that.$notification.success({message: "批量显示提示信息", duration: 2, description: res.message});
                that.loadData();
                that.onClearSelected();
              } else {
                that.$notification.error({message: "批量显示提示信息", duration: 2, description: res.message});
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    },
    handleIsDisplayNoBatch() {
      if (!this.url.isDisplayBatch) {
        this.$message.error("请设置url.isDisplayBatch!");
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！');
      } else {
        let ids = "";
        for (let a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ",";
        }
        let that = this;
        this.$confirm({
          title: "批量隐藏",
          content: "是否将选中数据都隐藏?",
          okText: '确认',
          cancelText: '取消',
          onOk: function () {
            that.loading = true;
            putAction(that.url.isDisplayBatch + "/" + ids + "/" + 0).then(res => {
              if (res.code === 200) {
                that.$notification.success({message: "批量隐藏提示信息", duration: 2, description: res.message});
                that.loadData();
                that.onClearSelected();
              } else {
                that.$notification.error({message: "批量隐藏提示信息", duration: 2, description: res.message});
              }
            }).finally(() => {
              that.loading = false;
            });
          }
        });
      }
    },
  }
};